package com.blast.apply.ui

import android.view.KeyEvent
import com.blast.apply.R
import com.blast.apply.presenter.AuthApplyPresenter
import com.wxl.common.base.AbsActivity
import com.wxl.common.http.CommonHttpUtil
import com.wxl.common.life.ViewModelQuick
import com.wxl.common.room.entity.DetonatorEntity
import com.wxl.common.util.KeyBoardUtil
import com.wxl.common.util.ObservableUtil
import kotlinx.android.synthetic.main.activity_under_apply_layout.*

class UnderLineApplyAuthActivity : AbsActivity() {


    override fun getCreateContentViewId(): Int {
        return R.layout.activity_under_apply_layout
    }

    override fun onCreateViewChanged() {
        setTopTitle("离线申请")
        CommonHttpUtil.getDetonatorInfo(object :
            ObservableUtil.Companion.OnNextCallback<DetonatorEntity>() {
            override fun onNext(t: DetonatorEntity) {
                underApplyCompanyText.text = t.buydeptid
                underApplyCompanyCode.text = t.buydept
                underApplyQbqCode.text = t.deptnum
            }
        })

        ViewModelQuick.observer(this, AuthApplyPresenter::class.java,underApplyRootView)

        underApplyBack.setOnClickListener {
            if (ViewModelQuick.get(this,AuthApplyPresenter::class.java).isLoading()) {
                return@setOnClickListener
            }
            finish()
        }

    }


    override fun onKeyDownEvent(keyCode: Int, event: KeyEvent?): Boolean {
        if (keyCode == KeyEvent.KEYCODE_F1 || keyCode == KeyEvent.KEYCODE_BACK) {
            underApplyBack.performClick()
        }
        if (keyCode == KeyEvent.KEYCODE_F4) {
            underApplySubmit.performClick()
        }
        return true
    }

    override fun addTitleSwitcher(): Boolean {
        return false
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        KeyBoardUtil.hideSoftInput(underApplyYzmEt)
    }
}